// import { uglify } from 'rollup-plugin-uglify'
import { terser } from 'rollup-plugin-terser'
import commonjs from 'rollup-plugin-commonjs'
// import babel from 'rollup-plugin-babel'
import nodePolyfills from 'rollup-plugin-polyfill-node'
import resolve from 'rollup-plugin-node-resolve'
import { eslint } from 'rollup-plugin-eslint'

// 项目配置
import * as libConfig from './lib.config.js'

export default {
  input: './src/JsEventsEmitter.js',
  output: [
    {
      file: `./dist/${libConfig.libName}.js`,
      name: libConfig.libName,
      format: 'umd',
      // 打包出来后顶部的注释介绍
      banner: libConfig.banner,
      globals: {
        fs: 'fs', // 指明 global.fs 即是外部依赖fs https://blog.csdn.net/qq_39075021/article/details/109113865
        path: 'path'
      },
      sourcemap: true
    },
    {
      file: `./dist/${libConfig.libName}.min.js`,
      name: `${libConfig.libName}.min`,
      // esm – 将软件包保存为 ES 模块文件，在现代浏览器中可以通过 <script type=module> 标签引入
      // umd – 通用模块定义，以amd，cjs 和 iife 为一体
      format: 'umd',
      // 打包出来后顶部的注释介绍
      banner: libConfig.banner,
      globals: {
        fs: 'fs', // 指明 global.fs 即是外部依赖fs https://blog.csdn.net/qq_39075021/article/details/109113865
        path: 'path'
      },
      plugins: [terser()]
    },
    {
      file: `./dist/${libConfig.libName}.esm.js`,
      name: `${libConfig.libName}.esm`,
      format: 'esm',
      // 打包出来后顶部的注释介绍
      banner: libConfig.banner,
      globals: {
        fs: 'fs', // 指明 global.fs 即是外部依赖fs https://blog.csdn.net/qq_39075021/article/details/109113865
        path: 'path'
      },
      sourcemap: true
    },
    {
      file: `./dist/${libConfig.libName}.esm.min.js`,
      name: `${libConfig.libName}.esm.min`,
      // esm – 将软件包保存为 ES 模块文件，在现代浏览器中可以通过 <script type=module> 标签引入
      // umd – 通用模块定义，以amd，cjs 和 iife 为一体
      format: 'esm',
      // 打包出来后顶部的注释介绍
      banner: libConfig.banner,
      globals: {
        fs: 'fs', // 指明 global.fs 即是外部依赖fs https://blog.csdn.net/qq_39075021/article/details/109113865
        path: 'path'
      },
      plugins: [terser()]
    }
  ],

  external: ['fs', 'path'],
  plugins: [
    resolve(),
    commonjs(),
    eslint(),
    // babel({
    //   exclude: 'node_modules/**'
    // }),
    nodePolyfills()
  ]
}
